<template>
    <div>
        <h1>登录页面</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="text" v-model="data.username">
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password"  v-model="data.password">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" @click="Deng">
                    </td>
                </tr>
            </thead>
        </table>
    </div>
</template>
<script setup lang="ts">
import {ref} from "vue";
import axios from "axios";
import { useRoute, useRouter } from "vue-router";
import { useuserStore } from "@/stores/user";
const user=useuserStore();
//实例化
const router=useRouter();
//moDEl
const data=ref({
    username:"",
    password:""
});
const Deng=()=>{
    axios.get("https://localhost:7076/api/Hui/Login",{params:data.value}).then(res=>{
        if(res.data.HId==-1)
        {
            alert("用户不存在");
        }
        if(res.data.HId==-2)
        {
            alert("密码错误");
        }
        if(res.data.HId>0)
        {
            alert("登陆成功");
             user.data.name=data.value.username;
            router.push({path:"/"});
        }
    })
}


</script>

<style scoped>

</style>